package shiyan;

import java.io.*;
import java.util.*;

public class shiyan1022 {
    public static void main(String[] args) {
        File file = new File("goods.txt");
        OutputStream out = null;
        try {
            out = new FileOutputStream(file, true);
        } catch (FileNotFoundException e) {
            System.out.println("写入错误"+e);
        }
        Scanner sc = null;
        int count = 0;
        double sum = 0;
        try {double price = 0;
            sc = new Scanner(file);
            sc.useDelimiter("[^0123456789.]+");
            while(sc.hasNextDouble()){
                price = sc.nextDouble();
                count++;
                sum = sum + price;
                System.out.println(price);
            }
            double aver = sum/count;
            String str = String.format("%.3f",aver);
            System.out.println("平均价格:"+str);
            out.write("\n".getBytes());
            out.write("平均价格".getBytes());
            out.write(str.getBytes());
        }
        catch(Exception e){
            System.out.println("读取错误"+e);
        }
    }
}